package com.ktjy.ktmall.controller;

import com.ktjy.common.annotation.Log;
import com.ktjy.common.core.controller.BaseController;
import com.ktjy.common.core.domain.AjaxResult;
import com.ktjy.common.core.page.TableDataInfo;
import com.ktjy.common.enums.BusinessType;
import com.ktjy.common.utils.poi.ExcelUtil;
import com.ktjy.ktmall.domain.TOrder;
import com.ktjy.ktmall.service.TOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单Controller
 *
 * @author ktjy
 * @date 2025-02-13
 */
@RestController
@RequestMapping("/ktmall/tOrder")
public class TorderController extends BaseController
{
    @Autowired
    private TOrderService tOrderService;

    /**
     * 查询订单列表
     */
    @PreAuthorize("@ss.hasPermi('ktmall:TOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(TOrder TOrder)
    {
        startPage();
        List<TOrder> list = tOrderService.selectOrderList(TOrder);
        return getDataTable(list);
    }


    /**
     * 导出订单列表
     */
    @PreAuthorize("@ss.hasPermi('ktmall:TOrder:export')")
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TOrder TOrder)
    {
        List<TOrder> list = tOrderService.list();
        ExcelUtil<TOrder> util = new ExcelUtil<TOrder>(TOrder.class);
        util.exportExcel(response, list, "订单数据");
    }

    /**
     * 获取订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('ktmall:TOrder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tOrderService.getById(id));
    }

    /**
     * 新增订单
     */
    @PreAuthorize("@ss.hasPermi('ktmall:TOrder:add')")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TOrder TOrder)
    {
        return toAjax(tOrderService.save(TOrder));
    }

    /**
     * 修改订单
     */
    @PreAuthorize("@ss.hasPermi('ktmall:TOrder:edit')")
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TOrder TOrder)
    {
        return toAjax(tOrderService.updateById(TOrder));
    }

    /**
     * 删除订单
     */
    @PreAuthorize("@ss.hasPermi('ktmall:TOrder:remove')")
    @Log(title = "订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Integer> ids)
    {
        return toAjax(tOrderService.removeByIds(ids));
    }
}